package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.mapper.OrderMapper;
import com.qf.pojo.Order;
import com.qf.service.OrderService;
import com.qf.vo.OrderItem;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderMapper orderMapper;

    @Override
    public List<Order> findAll() {
        return orderMapper.findAll();
    }

    @Override
    public Order findOne(int id) {
        return orderMapper.findOne(id);
    }

    @Override
    public Order addOrder(Order order) {
        orderMapper.addOrder(order);
        return order;
    }

    @Override
    public Order updateOrder(Order order) {
        orderMapper.update(order);
        return order;
    }

    @Override
    public Boolean deleteOrder(int id) {
        int i = orderMapper.delete(id);
        if (i>-1){
            return true;
        }
        return false;
    }

    @Override
    public PageInfo<OrderItem> findAlls(int uid,int p,int size) {
        System.out.println(p);
        System.out.println(size);
        PageHelper.startPage(p,size);
        List<OrderItem> alls = orderMapper.findAlls(uid);
        PageInfo<OrderItem> orderItemPageInfo = new PageInfo<>(alls);
        return orderItemPageInfo;
    }

    @Override
    public PageInfo<OrderItem> findAlls2(int p, int size) {
        PageHelper.startPage(p,size);
        List<OrderItem> alls2 = orderMapper.findAlls2();
        PageInfo<OrderItem> orderItemPageInfo = new PageInfo<>(alls2);
        return orderItemPageInfo;
    }
}
